# vim: ts=4:sw=4:syntax=perl
use gri_secmgr qw(get_user_name);

sub mm_validate_user_portal_access($) {
my $portal=$_[0];

	# Is this an actual portal - if not report an error...
	my $portal2=hex_to_string($portal);
	if(! $::GRI_FRONTEND->does_portal_exist($portal2)) {
		my $error="The portal '$portal2' does not exist.";
		my $error2="This typically occurs if a portal has been removed or the URL has been corrupted.";
		html_error({title=>"System Error",error=>$error,error2=>$error2,link=>undef});
		exit(0);
	}

	my $v=get_user_name();
	if(! $::GRI_FRONTEND->is_user_allowed($portal2,$v)) {
		my $n2=string_to_hex($v);
		my $l;
		$l=link_to_str("stdlink","New Request Access","form_portal_access_request","portal=$portal,user=$n2");
		my $error="You currently have not been granted access to view reports from the portal '$portal2'. Please click the link below to request access.";
		html_error({title=>"Access Denied - Request Access?",
			error=>$error,error2=>undef,
			"link"=>$l});
		exit(0);
	}
	return "";
}

1;

